Xceed Toolkit Plus for WPF v5.0 Documentation
In This Topic
    Providing unbound data
    In This Topic

    The following example demonstrates how to add Person data to a custom ObservableCollection of Person objects. 

    XAML
    Copy Code
    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
          xmlns:local="clr-namespace:Xceed.Wpf.Documentation"
          xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase">
      <Grid.Resources>
       <local:PersonObservableCollection x:Key="personData">
         <local:Person FirstName="Jenny"
                       LastName="Beland"
                       Occupation="Writer"/>
         <local:Person FirstName="Francois"
                       LastName="Carignan"
                       Occupation="Developer"/>
         <local:Person FirstName="Pascal"
                       LastName="Bourque"
                       Occupation="Developer"/>
         <local:Person FirstName="Michel"
                       LastName="Fortin"
                       Occupation="Developer"/>
         <local:Person FirstName="Marc"
                       LastName="Laroche"
                       Occupation="Developer"/>
         <local:Person FirstName="Pierre-Luc"
                       LastName="Ledoux"
                       Occupation="Developer"/>
         <local:Person FirstName="Mathieu"
                       LastName="Drimonakos"
                       Occupation="TechnicalSupport"/>
         <local:Person FirstName="Catherine"
                       LastName="Sauzede"
                       Occupation="Infograph"/>
       </local:PersonObservableCollection>
       <xcdg:DataGridCollectionViewSource x:Key="cvs_person"
                                          ItemType="{x:Type local:Person}"
                                          Source="{StaticResource personData}">
          <xcdg:DataGridCollectionViewSource.GroupDescriptions>
            <xcdg:DataGridGroupDescription PropertyName="Occupation"/>
          </xcdg:DataGridCollectionViewSource.GroupDescriptions>
          <xcdg:DataGridCollectionViewSource.SortDescriptions>
            <scm:SortDescription PropertyName="Occupation"
                                  Direction="Ascending"/>
          </xcdg:DataGridCollectionViewSource.SortDescriptions>
        </xcdg:DataGridCollectionViewSource>
      </Grid.Resources>
     <xcdg:DataGridControl x:Name="PersonGrid"
                           ItemsSource="{Binding Source={StaticResource cvs_person}}"/>
    </Grid>
    VB.NET
    Copy Code
    Dim people As New ObservableCollection( Of Person )()
    people.Add( New Person( "Jenny", "Beland" ) )
    people.Add( New Person( "Francois", "Carignan" ) )
    people.Add( New Person( "Jacques", "Bourque" ) )
    people.Add( New Person( "Pascal", "Bourque" ) )
    people.Add( New Person( "Marc", "Laroche" ) )
    people.Add( New Person( "Pierre-Luc", "Ledoux" ) )
    people.Add( New Person( "Catherine", "Sauzede" ) )
    people.Add( New Person( "Christian", "Nadeau" ) )
    Dim collectionView As New DataGridCollectionView( people, GetType( Person ) )
    dataGridControl.ItemsSource = collectionView
    C#
    Copy Code
    ObservableCollection<Person> people = new ObservableCollection<Person>();
    people.Add( new Person( "Jenny", "Beland" ) );
    people.Add( new Person( "Francois", "Carignan" ) );
    people.Add( new Person( "Jacques", "Bourque" ) );
    people.Add( new Person( "Pascal", "Bourque" ) );
    people.Add( new Person( "Marc", "Laroche" ) );
    people.Add( new Person( "Pierre-Luc", "Ledoux" ) );
    people.Add( new Person( "Catherine", "Sauzede" ) );
    people.Add( new Person( "Christian", "Nadeau" ) );
    DataGridCollectionView collectionView = new DataGridCollectionView( people, typeof( Person ) );
    dataGridControl.ItemsSource = collectionView;